//
//  STSellerListCollectionViewCell.m
//  赛拓
//
//  Created by 王磊 on 8/15/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STSellerListCollectionViewCell.h"
#import "STSellerBean.h"
#import "STGoodsView.h"
#import "STCommodityBean.h"
@interface STSellerListCollectionViewCell()<STBaseViewDelegate>

@property (nonatomic ,strong) UIImageView *iconImageView;

@property (nonatomic ,strong) UILabel *companyName;

@property (nonatomic ,strong) UILabel *content;

@property (nonatomic ,strong) UILabel *currentCom;

@property (nonatomic ,strong) STGoodsView *goodsView;

@property (nonatomic ,strong) STSellerBean *seller;

@property (nonatomic ,strong) UIButton *more;

@property (nonatomic ,strong) UIView *whiteView;
@end
@implementation STSellerListCollectionViewCell

//- (void)setFrame:(CGRect)frame {
//    
//    CGFloat margin = 20 * ST_RATE;
//    
//    frame.size.height -= margin;
//    
//    frame.origin.y += margin;
//    
//    [super setFrame:frame];
//}

- (void)configSubViews {

    [super configSubViews];
    
    UIView *whiteView = [UIView new];
    
    whiteView.backgroundColor = ST_WHITE_COLOR;
    
    self.whiteView = whiteView;
    
    [self addSubview:whiteView];
    
    UIImageView *iconImageView = [UIImageView new];
    
    self.iconImageView = iconImageView;
    
    [whiteView addSubview:iconImageView];
    
    iconImageView.layer.cornerRadius = 150 * ST_RATE / 2;
    
    iconImageView.layer.masksToBounds = true;
    
    UILabel *companyLabel = [UILabel new];
    
    self.companyName = companyLabel;
    
    companyLabel.textColor = ST_NAVI_COLOR;
    
    companyLabel.font = ST_13_FONT;
    
    [whiteView addSubview:companyLabel];
    
    UILabel *content = [UILabel new];
    
    self.content = content;
    
    content.font = ST_11_FONT;
    
    content.numberOfLines = 3;
    
    content.lineBreakMode = NSLineBreakByTruncatingTail;
    
    content.textColor = ST_999999_COLOR;
    
    [whiteView addSubview:content];
    
    UILabel *currentCom = [UILabel new];
    
    self.currentCom = currentCom;
    
    currentCom.font = ST_13_FONT;
    
    currentCom.backgroundColor = ST_BG_COLOR;
    
    currentCom.text = @"  在售商品";
    
    [self addSubview:currentCom];
    
    UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.more = more;
    
    [more addTarget:self action:@selector(moreCom) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:more];
    
    STGoodsView *goodsView = [STGoodsView instance];
    
    self.goodsView = goodsView;
    
    goodsView.mDelegate = self;
    
    [self addSubview:goodsView];
    
    self.backgroundColor = ST_CLEAR_COLOR;
}
- (void)updateData:(id)data {
    STSellerBean *seller = data;
    
    self.seller = seller;
    
    [self.iconImageView set_BGBannerImageViewWithString:seller.imgUrl];
    
    self.companyName.text = seller.name;
    
    self.content.text = seller.brief;
    
    if (seller.commodities.count) {
        self.goodsView.hidden = false;
        self.currentCom.hidden = false;
        self.more.hidden = false;
        
    }else {
        self.goodsView.hidden = true;
        self.currentCom.hidden = true;
        self.more.hidden = true;
    }
    NSArray *commodities = [STCommodityBean mj_objectArrayWithKeyValuesArray:seller.commodities];
    
    [self.goodsView updateData:commodities];
}
- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat margin = 25 * ST_RATE;
    
    self.whiteView.frame = CGRectMake(0, 0, ST_SCREEN_WIDTH, 200 * ST_RATE);
    
    self.iconImageView.frame = CGRectMake(margin, margin, 150 * ST_RATE, 150 * ST_RATE);
    
    self.companyName.frame = CGRectMake(CGRectGetMaxX(self.iconImageView.frame) + margin, CGRectGetMinX(self.iconImageView.frame), self.k_width - CGRectGetMaxX(self.iconImageView.frame) - margin * 2, 40 * ST_RATE);
    
    self.content.frame = CGRectMake(CGRectGetMaxX(self.iconImageView.frame) + margin, CGRectGetMaxY(self.companyName.frame) , self.k_width - CGRectGetMaxX(self.iconImageView.frame) - margin * 2, 110 * ST_RATE);
    
    if (self.seller.commodities.count) {
        
        self.currentCom.frame = CGRectMake(0, CGRectGetMaxY(self.whiteView.frame), self.k_width , 60 * ST_RATE);
        
        self.goodsView.frame = CGRectMake(0, CGRectGetMaxY(self.currentCom.frame) , self.k_width , 280 * ST_RATE);
    } else {
        
        self.currentCom.frame = CGRectMake(margin, CGRectGetMaxY(self.whiteView.frame), self.k_width - margin * 2, 0);
        
        self.goodsView.frame = CGRectMake(margin, CGRectGetMaxY(self.currentCom.frame) , self.k_width - margin * 2, 0);
    }
}
- (void)onItemClick:(STItemClickType)itemType withData:(id)data forIndexPath:(NSIndexPath *)indexPath {
    
    [self.mDelegate onItemClick:STItemClickTypeGoods withData:data forIndexPath:nil];
}

- (void)moreCom {
    
    
}


@end
